home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / cswsk10.zip / tcpecho.frm < prev    next >
Text File  |  1995-07-01  |  14KB  |  503 lines

  1. VERSION 2.00
  2. Begin Form MainForm 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   3  'Fixed Double
  5.    Caption         =   "Echo"
  6.    ClientHeight    =   4050
  7.    ClientLeft      =   1875
  8.    ClientTop       =   1935
  9.    ClientWidth     =   7095
  10.    FontBold        =   0   'False
  11.    FontItalic      =   0   'False
  12.    FontName        =   "MS Sans Serif"
  13.    FontSize        =   8.25
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   4740
  17.    Left            =   1815
  18.    LinkTopic       =   "Form1"
  19.    ScaleHeight     =   4050
  20.    ScaleWidth      =   7095
  21.    Top             =   1305
  22.    Width           =   7215
  23.    Begin Socket Socket2 
  24.       Backlog         =   1
  25.       Binary          =   -1  'True
  26.       Blocking        =   -1  'True
  27.       Broadcast       =   0   'False
  28.       BufferSize      =   0
  29.       HostAddress     =   ""
  30.       HostFile        =   ""
  31.       HostName        =   ""
  32.       InLine          =   0   'False
  33.       Interval        =   0
  34.       KeepAlive       =   0   'False
  35.       Left            =   600
  36.       Linger          =   0
  37.       LocalPort       =   0
  38.       LocalService    =   ""
  39.       Peek            =   0   'False
  40.       Protocol        =   0
  41.       RecvLen         =   0
  42.       RemotePort      =   0
  43.       RemoteService   =   ""
  44.       ReuseAddress    =   0   'False
  45.       Route           =   -1  'True
  46.       SendLen         =   0
  47.       TabIndex        =   15
  48.       Timeout         =   0
  49.       Top             =   3480
  50.       Type            =   1
  51.       Urgent          =   0   'False
  52.    End
  53.    Begin Socket Socket1 
  54.       Backlog         =   1
  55.       Binary          =   -1  'True
  56.       Blocking        =   -1  'True
  57.       Broadcast       =   0   'False
  58.       BufferSize      =   0
  59.       HostAddress     =   ""
  60.       HostFile        =   ""
  61.       HostName        =   ""
  62.       InLine          =   0   'False
  63.       Interval        =   0
  64.       KeepAlive       =   0   'False
  65.       Left            =   120
  66.       Linger          =   0
  67.       LocalPort       =   0
  68.       LocalService    =   ""
  69.       Peek            =   0   'False
  70.       Protocol        =   0
  71.       RecvLen         =   0
  72.       RemotePort      =   0
  73.       RemoteService   =   ""
  74.       ReuseAddress    =   0   'False
  75.       Route           =   -1  'True
  76.       SendLen         =   0
  77.       TabIndex        =   14
  78.       Timeout         =   0
  79.       Top             =   3480
  80.       Type            =   1
  81.       Urgent          =   0   'False
  82.    End
  83.    Begin CommandButton CancelButton 
  84.       Caption         =   "Cancel"
  85.       Height          =   375
  86.       Left            =   4080
  87.       TabIndex        =   11
  88.       Top             =   3480
  89.       Width           =   1215
  90.    End
  91.    Begin CommandButton ActionButton 
  92.       Caption         =   "Connect"
  93.       Height          =   375
  94.       Left            =   1800
  95.       TabIndex        =   10
  96.       Top             =   3480
  97.       Width           =   1215
  98.    End
  99.    Begin TextBox SocketInput 
  100.       BackColor       =   &H00C0C0C0&
  101.       Height          =   285
  102.       Left            =   120
  103.       TabIndex        =   9
  104.       Top             =   3000
  105.       Width           =   6855
  106.    End
  107.    Begin ListBox SocketOutput 
  108.       BackColor       =   &H00C0C0C0&
  109.       FontBold        =   0   'False
  110.       FontItalic      =   0   'False
  111.       FontName        =   "Courier New"
  112.       FontSize        =   9.75
  113.       FontStrikethru  =   0   'False
  114.       FontUnderline   =   0   'False
  115.       Height          =   1230
  116.       Left            =   120
  117.       TabIndex        =   8
  118.       Top             =   1680
  119.       Width           =   6855
  120.    End
  121.    Begin Frame ServiceFrame 
  122.       BackColor       =   &H00C0C0C0&
  123.       Caption         =   "Service"
  124.       Height          =   1455
  125.       Left            =   3600
  126.       TabIndex        =   13
  127.       Top             =   120
  128.       Width           =   3375
  129.       Begin SpinButton Spin1 
  130.          Delay           =   150
  131.          Height          =   285
  132.          Left            =   1560
  133.          Top             =   840
  134.          Width           =   255
  135.       End
  136.       Begin TextBox ServicePort 
  137.          BackColor       =   &H00C0C0C0&
  138.          Height          =   285
  139.          Left            =   840
  140.          TabIndex        =   7
  141.          Top             =   840
  142.          Width           =   735
  143.       End
  144.       Begin TextBox ServiceName 
  145.          BackColor       =   &H00C0C0C0&
  146.          Height          =   285
  147.          Left            =   840
  148.          TabIndex        =   5
  149.          Top             =   480
  150.          Width           =   2175
  151.       End
  152.       Begin Label Label4 
  153.          BackStyle       =   0  'Transparent
  154.          Caption         =   "&Port:"
  155.          Height          =   255
  156.          Left            =   120
  157.          TabIndex        =   6
  158.          Top             =   840
  159.          Width           =   495
  160.       End
  161.       Begin Label Label3 
  162.          BackStyle       =   0  'Transparent
  163.          Caption         =   "&Name:"
  164.          Height          =   255
  165.          Left            =   120
  166.          TabIndex        =   4
  167.          Top             =   480
  168.          Width           =   615
  169.       End
  170.    End
  171.    Begin Frame RemoteFrame 
  172.       BackColor       =   &H00C0C0C0&
  173.       Caption         =   "System"
  174.       Height          =   1455
  175.       Left            =   120
  176.       TabIndex        =   12
  177.       Top             =   120
  178.       Width           =   3375
  179.       Begin ComboBox Hostname 
  180.          BackColor       =   &H00C0C0C0&
  181.          Height          =   300
  182.          Left            =   1200
  183.          Sorted          =   -1  'True
  184.          TabIndex        =   1
  185.          Top             =   480
  186.          Width           =   1935
  187.       End
  188.       Begin TextBox IPAddress 
  189.          BackColor       =   &H00C0C0C0&
  190.          Height          =   285
  191.          Left            =   1200
  192.          TabIndex        =   3
  193.          Top             =   840
  194.          Width           =   1575
  195.       End
  196.       Begin Label Label2 
  197.          BackStyle       =   0  'Transparent
  198.          Caption         =   "IP &Address:"
  199.          Height          =   255
  200.          Left            =   120
  201.          TabIndex        =   2
  202.          Top             =   840
  203.          Width           =   1095
  204.       End
  205.       Begin Label Label1 
  206.          BackStyle       =   0  'Transparent
  207.          Caption         =   "&Hostname:"
  208.          Height          =   255
  209.          Left            =   120
  210.          TabIndex        =   0
  211.          Top             =   480
  212.          Width           =   975
  213.       End
  214.    End
  215.    Begin Menu FileMenu 
  216.       Caption         =   "&File"
  217.       Begin Menu ExitApp 
  218.          Caption         =   "E&xit"
  219.       End
  220.    End
  221.    Begin Menu OptionsMenu 
  222.       Caption         =   "&Options"
  223.       Begin Menu ServerOption 
  224.          Caption         =   "Echo Server"
  225.       End
  226.    End
  227. End
  228.  
  229. Sub ActionButton_Click ()
  230.     If Not Socket1.Connected Then
  231.         On Error Resume Next
  232.         MainForm.MousePointer = 11
  233.         HostName.Text = Trim$(HostName.Text)
  234.         If Len(HostName.Text) > 0 Then
  235.             Socket1.HostName = HostName.Text
  236.             IPAddress.Text = Socket1.HostAddress
  237.         Else
  238.             Socket1.HostAddress = Trim$(IPAddress.Text)
  239.             HostName.Text = Socket1.HostName
  240.         End If
  241.         ServiceName.Text = Trim$(ServiceName.Text)
  242.         If Len(ServiceName.Text) > 0 Then
  243.             Socket1.RemoteService = ServiceName.Text
  244.             ServicePort.Text = Trim$(Str$(Socket1.RemotePort))
  245.         Else
  246.             Socket1.RemotePort = Val(Trim$(ServicePort.Text))
  247.             ServiceName.Text = Socket1.RemoteService
  248.         End If
  249.         Socket1.Action = SOCKET_CONNECT
  250.         If Err <> 0 Then Exit Sub
  251.         ActionButton.Enabled = False
  252.         ActionButton.Default = False
  253.     Else
  254.         Socket1.Action = SOCKET_CLOSE
  255.         ActionButton.Caption = "Connect"
  256.         ActionButton.Default = True
  257.         HostName.SetFocus
  258.     End If
  259.     Exit Sub
  260. End Sub
  261.  
  262. Sub CancelButton_Click ()
  263.     Unload MainForm
  264. End Sub
  265.  
  266. Sub ExitApp_Click ()
  267.     Unload MainForm
  268. End Sub
  269.  
  270. Sub Form_Load ()
  271.     '
  272.     ' Initialize the socket control
  273.     '
  274.     Socket1.AddressFamily = AF_INET
  275.     Socket1.Binary = False
  276.     Socket1.Blocking = False
  277.     Socket1.BufferSize = 1024
  278.     Socket1.Protocol = IPPROTO_IP
  279.     Socket1.Type = SOCK_STREAM
  280.     Socket1.RemoteService = "echo"
  281.  
  282.     Socket2.AddressFamily = AF_INET
  283.     Socket2.Binary = True
  284.     Socket2.Blocking = False
  285.     Socket2.HostAddress = INADDR_ANY
  286.     Socket2.Protocol = IPPROTO_IP
  287.     Socket2.Type = SOCK_STREAM
  288.     Socket2.LocalService = "echo"
  289.     
  290.     '
  291.     ' Initialize hostname combo box
  292.     '
  293.     On Error Resume Next
  294.     Socket1.HostFile = "HOSTS"
  295.     If Err = 0 Then
  296.         Host$ = Socket1.GetFirstHost
  297.         While Host$ <> ""
  298.             HostName.AddItem Host$
  299.             Host$ = Socket1.GetNextHost
  300.         Wend
  301.     End If
  302.     Socket1.HostFile = ""
  303.  
  304.     '
  305.     ' Initialize the other controls
  306.     '
  307.     ActionButton.Caption = "Connect"
  308.     ActionButton.Default = True
  309.     ActionButton.Enabled = False
  310.     ServiceName.Text = Socket1.RemoteService
  311.     ServicePort.Text = Trim$(Str$(Socket1.RemotePort))
  312. End Sub
  313.  
  314. Sub Form_Unload (Cancel As Integer)
  315.     If Socket1.Connected Then Socket1.Action = SOCKET_CLOSE
  316.     If Socket2.Listening Or Socket2.Connected Then Socket2.Action = SOCKET_CLOSE
  317.     End
  318. End Sub
  319.  
  320. Sub Hostname_Change ()
  321.     If Len(HostName.Text) > 0 Or Len(IPAddress.Text) > 0 Then
  322.         ActionButton.Enabled = True
  323.     Else
  324.         ActionButton.Enabled = False
  325.     End If
  326. End Sub
  327.  
  328. Sub Hostname_GotFocus ()
  329.     HostName.SelStart = 0
  330.     HostName.SelLength = Len(HostName.Text)
  331. End Sub
  332.  
  333. Sub Hostname_LostFocus ()
  334.     On Error Resume Next
  335.  
  336.     Socket1.HostName = Trim(HostName.Text)
  337.     IPAddress.Text = Socket1.HostAddress
  338.     If Err = WSANO_DATA Then IPAddress.Text = ""
  339.     Exit Sub
  340. End Sub
  341.  
  342. Sub IPAddress_Change ()
  343.     If Len(HostName.Text) > 0 Or Len(IPAddress.Text) > 0 Then
  344.         ActionButton.Enabled = True
  345.     Else
  346.         ActionButton.Enabled = False
  347.     End If
  348. End Sub
  349.  
  350. Sub IPAddress_GotFocus ()
  351.     IPAddress.SelStart = 0
  352.     IPAddress.SelLength = Len(IPAddress.Text)
  353. End Sub
  354.  
  355. Sub IPAddress_LostFocus ()
  356.     On Error Resume Next
  357.     
  358.     Socket1.HostAddress = Trim(IPAddress.Text)
  359.     HostName.Text = Socket1.HostName
  360.     If Err = WSANO_DATA Then
  361.         MsgBox "That IP address is invalid"
  362.         Socket1.HostAddress = ""
  363.     End If
  364.     Exit Sub
  365. End Sub
  366.  
  367. Sub ServerOption_Click ()
  368.     If Not Socket2.Connected Then
  369.         ServerOption.Checked = Not ServerOption.Checked
  370.         If ServerOption.Checked Then
  371.             Socket2.Action = SOCKET_LISTEN
  372.         Else
  373.             Socket2.Action = SOCKET_CLOSE
  374.         End If
  375.     End If
  376. End Sub
  377.  
  378. Sub ServiceName_GotFocus ()
  379.     ServiceName.SelStart = 0
  380.     ServiceName.SelLength = Len(ServiceName.Text)
  381. End Sub
  382.  
  383. Sub ServiceName_LostFocus ()
  384.     On Error GoTo BadName
  385.  
  386.     Socket1.RemoteService = Trim(ServiceName.Text)
  387.     ServicePort.Text = Socket1.RemotePort
  388.     Exit Sub
  389.  
  390. BadName:
  391.     ServicePort.Text = ""
  392.     ServiceName.SetFocus
  393.     Exit Sub
  394. End Sub
  395.  
  396. Sub ServicePort_GotFocus ()
  397.     ServicePort.SelStart = 0
  398.     ServicePort.SelLength = Len(ServicePort.Text)
  399. End Sub
  400.  
  401. Sub ServicePort_KeyPress (KeyAscii As Integer)
  402.     If KeyAscii > Asc("9") Then
  403.         KeyAscii = 0
  404.         Beep
  405.     ElseIf KeyAscii >= Asc("0") And Len(ServicePort.Text) > 5 Then
  406.         KeyAscii = 0
  407.         Beep
  408.     End If
  409. End Sub
  410.  
  411. Sub ServicePort_LostFocus ()
  412.     On Error GoTo BadPort
  413.  
  414.     Socket1.RemotePort = Val(Trim(ServicePort.Text))
  415.     ServiceName.Text = Socket1.RemoteService
  416.     Exit Sub
  417.  
  418. BadPort:
  419.     ServiceName.Text = ""
  420.     ServicePort.SetFocus
  421.     Exit Sub
  422. End Sub
  423.  
  424. Sub Socket1_Close ()
  425.     Socket1.Action = SOCKET_CLOSE
  426.     ActionButton.Caption = "Connect"
  427.     ActionButton.Default = True
  428.     HostName.SetFocus
  429. End Sub
  430.  
  431. Sub Socket1_Connect ()
  432.     MainForm.MousePointer = 0
  433.     ActionButton.Caption = "Close"
  434.     ActionButton.Enabled = True
  435.     SocketInput.SetFocus
  436. End Sub
  437.  
  438. Sub Socket1_Error (ErrCode As Integer, ErrMsg As String, Response As Integer)
  439.     If Socket1.Action = SOCKET_CONNECT Then
  440.         MsgBox ErrMsg, 0, "Connect"
  441.         Response = SOCKET_ERRIGNORE
  442.         Exit Sub
  443.     End If
  444. End Sub
  445.  
  446. Sub Socket1_Read (DataLength As Integer, IsUrgent As Integer)
  447.     Socket1.RecvLen = DataLength
  448.     SocketOutput.AddItem Socket1.RecvData
  449.     SocketOutput.ListIndex = SocketOutput.ListCount - 1
  450.     SocketOutput.Selected(SocketOutput.ListIndex) = False
  451. End Sub
  452.  
  453. Sub Socket2_Accept (SocketId As Integer)
  454.     Socket2.Action = SOCKET_ACCEPT
  455. End Sub
  456.  
  457. Sub Socket2_Close ()
  458.     Socket2.Action = SOCKET_CLOSE
  459.     If ServerOption.Checked Then Socket2.Action = SOCKET_LISTEN
  460. End Sub
  461.  
  462. Sub Socket2_Read (DataLength As Integer, IsUrgent As Integer)
  463.     Socket2.RecvLen = DataLength
  464.     Socket2.SendLen = DataLength
  465.     Socket2.SendData = Socket2.RecvData
  466. End Sub
  467.  
  468. Sub SocketInput_KeyPress (KeyAscii As Integer)
  469.     If KeyAscii = 13 Then
  470.         KeyAscii = 0
  471.         Socket1.SendLen = Len(SocketInput.Text) + 2
  472.         Socket1.SendData = SocketInput.Text & Chr(13) & Chr(10)
  473.         SocketInput.Text = ""
  474.     End If
  475. End Sub
  476.  
  477. Sub Spin1_SpinDown ()
  478.     Dim Value As Integer
  479.  
  480.     Value = Val(ServicePort.Text) - 1
  481.     If Value >= 0 Then
  482.         Socket1.RemotePort = Value
  483.         ServiceName.Text = Socket1.RemoteService
  484.         ServicePort.Text = Trim(Str(Value))
  485.     Else
  486.         Beep
  487.     End If
  488. End Sub
  489.  
  490. Sub Spin1_SpinUp ()
  491.     Dim Value As Integer
  492.  
  493.     Value = Val(ServicePort.Text) + 1
  494.     If Value > 0 Then
  495.         Socket1.RemotePort = Value
  496.         ServiceName.Text = Socket1.RemoteService
  497.         ServicePort.Text = Trim(Str(Value))
  498.     Else
  499.         Beep
  500.     End If
  501. End Sub
  502.  
  503.